from django.db import models

# Create your models here.
from django.db import models

class Score(models.Model):
    """成绩"""
    student = models.ForeignKey('student.Student', on_delete=models.CASCADE,
                                related_name='scores',
                                verbose_name='学生')
    course = models.ForeignKey('course.Course', on_delete=models.CASCADE,
                               related_name='scores',
                               verbose_name='课程')
    value = models.FloatField(verbose_name='成绩')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='录入时间')

    class Meta:
        db_table = 'tb_score'
        unique_together = ('student', 'course')   # 一个学生一门课只有一条成绩
        verbose_name = '成绩'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f'{self.student.name}-{self.course.name}:{self.value}'